/**
 * 参数设置管理初始化
 */
var PartnerList = {
    id: "PartnerListTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
PartnerList.initColumn = function () {
    var columns = [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle',width:'50px'},
        {title: '状态', field: 'zhuangtai', align: 'center', valign: 'middle'},
        {title: '姓名', field: 'disUserName', align: 'center', valign: 'middle'},
        {title: '绑定手机', field: 'binding_phone', align: 'center', valign: 'middle'},
        {title: '推荐码', field: 'dis_recommendation_no', align: 'center', valign: 'middle'},
        {title: '身份证号码', field: 'idNo', align: 'center', valign: 'middle'},
        {title: '推荐人推荐码', field: 'dis_recomm_pcode', align: 'center', valign: 'middle'},
        {title: '矿机数量', field: 'robNum', align: 'center', valign: 'middle'},
        {title: '商铺数量', field: 'shopNum', align: 'center', valign: 'middle'},
        {title: '单品数量', field: 'cellNum', align: 'center', valign: 'middle'},
        {title: '百星数量', field: 'whiteNum', align: 'center', valign: 'middle'},
        {title: '品牌数量', field: 'starNum', align: 'center', valign: 'middle'},
        {title: '加入时间', field: 'addTime', align: 'center', sortable: true,valign: 'middle'},
        {title: '停用时间', field: 'stupUse_time', align: 'center', valign: 'middle'},
    ]
    return columns;
};

/**
 * 检查是否选中
 */
PartnerList.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        PartnerList.seItem = selected[0];
        return true;

    }
};

/**
 * 检查是否可以停用
 */
PartnerList.checkstopuse = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    PartnerList.seItem = selected[0];
    if(PartnerList.seItem.zhuangtai == "停用"){
        Feng.info("这个合伙人状态已经是停用");
        return false;
    }else{
        PartnerList.seItem = selected[0];
        return true;

    }
};

/**
 * 检查是否可以启用
 */
PartnerList.checkuse = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    PartnerList.seItem = selected[0];
    if(PartnerList.seItem.zhuangtai == "启用"){
        Feng.info("这个合伙人状态已经是启用");
        return false;
    }else{
        return true;
    }
};

/**
 * 停用确认框
 */
PartnerList.PartnerStopUse = function () {
    if(this.check()) {
        if(this.checkstopuse()) {
        $.confirm({
            title: '系统提示',
            content: '是否确定停用此合伙人,登录账号:' + PartnerList.seItem.binding_phone,
            buttons: {
                ok: {
                    text: '确认',
                    btnClass: 'btn-primary',
                    action: PartnerList.stopUse()
                },
                cancel: {
                    text: '取消',
                    btnClass: 'btn-primary',
                    action: function () {
                        // button action.
                    }
                }
            }
        });
    }
    }
};

/**
 * 启用确认框
 */
PartnerList.PartnerUse = function () {
    if(this.check()) {
        if(this.checkuse()) {
        $.confirm({
            title: '系统提示',
            content: '是否确定启用此合伙人,登录账号:' + PartnerList.seItem.binding_phone,
            buttons: {
                ok: {
                    text: '确认',
                    btnClass: 'btn-primary',
                    action: PartnerList.Use()
                },
                cancel: {
                    text: '取消',
                    btnClass: 'btn-primary',
                    action: function () {
                        // button action.
                    }
                },
            }
        });
     }
    }
};

/**
 * 打开查看参数设置详情
 */
PartnerList.PartnerUpdate = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '修改',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/partnerList/partner_update/' + PartnerList.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 查看合同详情
 */
PartnerList.PartnerContractDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '合同详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/partnerList/contractDetail/' + PartnerList.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 停用
 */
PartnerList.StopUse = function () {
    if (this.check()) {

            var ajax = new $ax(Feng.ctxPath + "/partnerList/stopUse", function (data) {
                Feng.success("停用成功!");
                PartnerList.table.refresh();
            }, function (data) {
                Feng.error("失败!" + data.responseJSON.message + "!");
            });
            ajax.set("id", this.seItem.id);
            ajax.start();

    }
};

/**
 * 启用
 */
PartnerList.Use = function () {
    if (this.check()) {

            var ajax = new $ax(Feng.ctxPath + "/partnerList/use", function (data) {
                Feng.success("启用成功!");
                PartnerList.table.refresh();
            }, function (data) {
                Feng.error("失败!" + data.responseJSON.message + "!");
            });
            ajax.set("id", this.seItem.id);
            ajax.start();

    }
};

/**
 * 查询参数设置列表
 */
PartnerList.search = function () {
    var queryData = {};
    queryData['bindingPhone'] = $("#bindingPhone").val();
    queryData['recomm_pcode'] = $("#recomm_pcode").val();
    queryData['status'] = $("#status").val();
    queryData['disUsername'] = $("#disUsername").val();
    queryData['jointime'] = $("#jointime").val().replace("/","-");
    if($("#jointime").val() != "") {
        if($("#jointime_end").val() == "") {
            Feng.info("请选择结束时间！");
            return false;
        }else{
            queryData['jointime_end'] = $("#jointime_end").val().replace("/","-");
        }
    }
    PartnerList.table.refresh({query: queryData});
};

$(function () {
    $("#jointime").attr('type','date');
    $("#jointime_end").attr('type','date');
    var defaultColunms = PartnerList.initColumn();
    var table = new BSTable(PartnerList.id, "/partnerList/list", defaultColunms);
    table.setPaginationType("client");
    PartnerList.table = table.init();
});



